package com.irate.adapter;

import java.util.List;

import com.irate.activity.R;
import com.irate.model.RatingCategory;
import com.irate.provider.ContentManager;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class RatingCategoryAdapter extends BaseAdapter {

	protected List<RatingCategory> category_data;

	public RatingCategoryAdapter() {
		category_data = ContentManager.getInstance().getListRatingCategory();
	}

	@Override
	public int getCount() {

		return category_data.size();
	}

	@Override
	public Object getItem(int arg0) {
		return category_data.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {

		return arg0;
	}

	@Override
	public View getView(int position, View converView, ViewGroup parent) {

		if (converView == null) {
			LayoutInflater inflat = LayoutInflater.from(parent.getContext());
			converView = inflat.inflate(R.layout.item_category, null);
		}

		TextView tv = (TextView) converView.findViewById(R.id.category_title);

		tv.setText(category_data.get(position).getCategory_name());
		tv.setPadding(15, 15, 15, 15);

		if (ContentManager.getInstance().getCategory_index_selected() != -1
				&& ContentManager.getInstance().getCategory_index_selected() == position) {

			converView.setBackgroundColor(Color.rgb(139, 137, 130));

		} else {
			converView.setBackgroundDrawable(parent.getContext().getResources()
					.getDrawable(R.drawable.category_item_background));
		}

		return converView;
	}

}
